package cn.wolfcode.mp.service.impl;

import cn.wolfcode.mp.domain.Role;
import cn.wolfcode.mp.domain.RolePermission;
import cn.wolfcode.mp.mapper.RoleMapper;
import cn.wolfcode.mp.mapper.RolePermissionMapper;
import cn.wolfcode.mp.service.IRoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {

    @Autowired
    private RolePermissionMapper rolePermissionMapper;

    @Override
    public boolean permission(Long roleId) {
        List<RolePermission> rolePermissions = rolePermissionMapper.selectList(new QueryWrapper<RolePermission>()
                .lambda()
                .eq(RolePermission::getRoleId, roleId)
        );

        if (rolePermissions.size() != 0) {
            return true;
        }

        return false;
    }
}
